import java.io.*;

// Imdb encoding: ISO-8859-1
class CachedBinaryReader
{
  CachedBinaryReader(String filePath)
  {
    ready = false;
    try {
      FileInputStream file = new FileInputStream(filePath);
      BufferedInputStream bin = new BufferedInputStream(file, BUFFER_SIZE);
      DataInputStream dis = new DataInputStream(bin);
      input = dis;     
      ready = true;
      errorFlag = false;
    } catch (Exception e)
    {
      println("ERROR in opening file: " + e.getMessage());
    }
  }
  
  boolean isReady()
  {
    return ready;
  }
  
  int readInt() throws EOFException
  {
    int ret;
    try
    {
      ret = input.readInt();
    }
    catch (IOException e)
    {
      if (e instanceof EOFException)  {
        throw (EOFException) e;
      }
      else {
        println("ERROR reading stream: " + e.getMessage());
        e.printStackTrace();
        errorFlag = true;
        ret = 0;
      }
    }
    return ret;
  }
  
  void closeFile()
  {
    try {
      input.close();
    } catch (Exception e) {
      println("ERROR in closeFile: " + e.getMessage());
    }
  }
  
  boolean isError() { return errorFlag; }
  
  private boolean errorFlag;
  private boolean ready;
  private DataInputStream input;
}
